﻿using System;
using System.Text;

namespace Bouyei.Geo.Converters
{
    public class JsonExtensions
    {
        //private Encoding encoding = Encoding.UTF8;
        public JsonExtensions(Encoding encoding=null)
        {
            //if(encoding!=null)
            //{
            //    this.encoding = encoding;
            //}
        }

        public string ConvertFrom<T>(T objectValue)
        {
           return System.Text.Json.JsonSerializer.Serialize(objectValue,new System.Text.Json.JsonSerializerOptions() { 
            WriteIndented=false
           });
        }

        public T ConvertTo<T>(string jsonString)
        {
            return System.Text.Json.JsonSerializer.Deserialize<T>(jsonString,new System.Text.Json.JsonSerializerOptions() { 
             Encoder= System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            });
        }
    }
}
